/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package MODEL.DAO;

import MODEL.POJO.ChiTietHoaDonPOJO;
import MODEL.UTIL.MySqlDataAccessHelper;

/**
 *
 * @author kijoo
 */
public class ChiTietHoaDonDAO {

    public static boolean ThemChiTietHoaDon(ChiTietHoaDonPOJO cthd) {
        boolean kq = false;
        try {
            String sql = String.format("INSERT INTO CHITIETHOADON (`IDHOADON`,`IDCHITIETSANPHAM`,`SOLUONGBAN`) VALUES ('%s','%s','%d')", cthd.getIdhoadon(), cthd.getIdchitietsanpham(), cthd.getSoluongban());
            MySqlDataAccessHelper helper = new MySqlDataAccessHelper();
            helper.Open();
            int n = helper.executeUpdate(sql);
            if (n == 1) {
                kq = true;
            }
            helper.Close();
        } catch (Exception ex) {
            System.err.println(ex);
        }
        return kq;
    }

    public static boolean XoaChiTietHoaDon(int idhoadon) {
        boolean kq = false;
        try {
            String sql = String.format("DELETE FROM CHITIETHOADON WHERE IDHOADON='%d'", idhoadon);
            MySqlDataAccessHelper helper = new MySqlDataAccessHelper();
            helper.Open();
            int n = helper.executeUpdate(sql);
            if (n == 1) {
                kq = true;
            }
            helper.Close();
        } catch (Exception ex) {
            System.err.println(ex);
        }
        return kq;
    }
}
